//
//  LeaderDetailController.m
//  PropertyMananger
//
//  Created by Mansion on 17/3/5.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "LeaderDetailController.h"
#import "LeaderRepairController.h"
#import "LeaderComplainController.h"

@interface LeaderDetailController ()



@end

@implementation LeaderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"本月工单进度明细"];
    
    LeaderRepairController * repairVC = [[LeaderRepairController alloc]init];
    repairVC.selectedTime = self.selectedTime;
    DLog(@"选择的时间 === %@",self.selectedTime);
    [self addChildViewController:repairVC];
   
    LeaderComplainController * complainVC = [[LeaderComplainController alloc]init];
    
         complainVC.selectedTime = self.selectedTime;
 
    [self addChildViewController:complainVC];
    
    NSArray * childVC = @[repairVC,complainVC];
    
    NSArray * title_arr = @[@"报修单",@"投诉单"];
    
    self.bottomSView = [[SGSegmentedControlBottomView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.bottomSView.childViewController = childVC;
    self.bottomSView.backgroundColor = [UIColor clearColor];
    self.bottomSView.delegate = self;
    //_bottomView.scrollEnabled = NO;
    [self.view addSubview:self.bottomSView];
    
    self.topSView = [SGSegmentedControlStatic segmentedControlWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50) delegate:self childVcTitle:title_arr indicatorIsFull:NO];
    // 必须实现的方法
    [self.topSView SG_setUpSegmentedControlType:^(SGSegmentedControlStaticType *segmentedControlStaticType, NSArray *__autoreleasing *nomalImageArr, NSArray *__autoreleasing *selectedImageArr) {
        
    }];
    //指定下标
    self.topSView.selectedIndex = self.index;
    [self.view addSubview:self.topSView];
    
    DLog(@"传过来的 === %ld",self.index);
    
}

- (void)SGSegmentedControlStatic:(SGSegmentedControlStatic *)segmentedControlStatic didSelectTitleAtIndex:(NSInteger)index {
    NSLog(@"index - - %ld", (long)index);
    
   //  index = self.index;
    
    // 计算滚动的位置
    CGFloat offsetX = index * self.view.frame.size.width;
    self.bottomSView.contentOffset = CGPointMake(offsetX, 0);
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    // 计算滚动到哪一页
    NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
    
   
    
    // 1.添加子控制器view
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
    
    // 2.把对应的标题选中
    [self.topSView changeThePositionOfTheSelectedBtnWithScrollView:scrollView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
    
}


@end
